package jm.mq.producers;

import com.rabbitmq.client.Channel;
import jm.mq.utils.RabbitMQUtils;

import java.util.Scanner;

/**
 * @Description 生产者代码
 * @date 2022/3/5 10:15
 */
public class Producer {

    private static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMQUtils.getChannel();


        // 产生队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        // 消息体
        Scanner scanner = new Scanner(System.in);
        int i = 1;
        while (scanner.hasNext()){
            String msg = scanner.next();
            msg = msg + i;
            channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
            System.out.println("发送成功：" + msg);
        }


        System.out.println("----------==========发送完毕==========----------");
    }

}
